﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LittleSolution
{
    public partial class frmAddObject : Form
    {
        public frmAddObject()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (IsValidObjectName())
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("You must enter Object Name before accept","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }                                                                                                                
        }

        private bool IsValidObjectName()
        {
            return !String.IsNullOrEmpty(tbxObjectName.Text);
        }
        public String GetObjectName()
        {
            return tbxObjectName.Text;
        }

        private void frmAddObject_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Escape)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            else if (e.KeyCode==Keys.Enter)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void frmAddObject_Load(object sender, EventArgs e)
        {
            tbxObjectName.Focus();
        }
    }
}
